package com.power.algorithm;

import java.util.HashMap;

/**
 * @description:
 * @author: jiangnan
 * @time: 2021/6/17 5:26 下午
 */
public class Solution36 {

    public boolean isValidSudoku(char[][] board) {
        HashMap<Integer, Integer> rows[] = new HashMap[9];
        HashMap<Integer, Integer> colume[] = new HashMap[9];
        HashMap<Integer, Integer> box[] = new HashMap[9];

        for (int i = 0; i < 9; i++) {
            rows[i] = new HashMap();
            colume[i] = new HashMap();
            box[i] = new HashMap();
        }
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board.length; j++) {
                if (board[i][j] != '.') {
                    int n = (int) board[i][j];
                    int num = i / 3 * 3 + j / 3;
                    rows[i].put(n, rows[i].getOrDefault(n, 0) + 1);
                    colume[j].put(n, colume[j].getOrDefault(n, 0) + 1);
                    box[num].put(n, box[num].getOrDefault(n, 0) + 1);

                    if (rows[i].get(n) > 1 || colume[j].get(n) > 1 || box[num].get(n) > 1) {
                        return false;
                    }
                }
            }
        }

        return true;
    }

}
